package com.youlu.campus.website.controller;

import com.youlu.campus.common.base.QResult;
import com.youlu.campus.website.common.enums.PlatformType;
import com.youlu.campus.website.entity.CompanyDynamicDetail;
import com.youlu.campus.website.entity.CompanyDynamicType;
import com.youlu.campus.website.entity.CompanyDynamicTypeMonthVo;
import com.youlu.campus.website.service.CompanyDynamicDetailService;
import com.youlu.campus.website.service.CompanyDynamicService;
import com.youlu.campus.website.service.CompanyDynamicTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 公司动态 控制器
 */
@RestController
@RequestMapping(value = "/api/campany/dynamic")
public class CompanyDynamicController {

    @Autowired
    private CompanyDynamicService companyDynamicService;

    @Autowired
    private CompanyDynamicDetailService companyDynamicDetailService;


    @Autowired
    private CompanyDynamicTypeService companyDynamicTypeService;

    /**
     * 获取当前月 公司动态vo
     *
     * @return
     */
    @GetMapping("/month/find-current")
    public QResult<CompanyDynamicTypeMonthVo> getCurrentMonthDynamic(@RequestHeader("platform") PlatformType platform) {
        return QResult.success(companyDynamicService.getCurrentMonthDynamic(platform));
    }

    /**
     * 获取所有公司动态类型
     *
     * @return
     */
    @GetMapping("/type/find-all")
    public QResult<List<CompanyDynamicType>> typeFindAll() {
        return QResult.success(companyDynamicTypeService.getAllTypes());
    }


    /**
     * 根据类型查询
     *
     * @return
     */
    @GetMapping("/find-type")
    public QResult<List<CompanyDynamicDetail>> findByTypeAndTitleAndPlatformType(@RequestHeader(value = "platform", required = false) PlatformType platform, @RequestParam String type, @RequestParam(required = false) String title) {
        return QResult.success(companyDynamicDetailService.findByTypeAndTitleAndPlatformType(platform, type, title));
    }
}